/*开发者:谢先博
 *开发时间:
 *修改:2017-7-10 宋成恩 修改createUploadUrl函数,返回上传的地址
 *
 */
import axios from 'axios'
import { getNowFormatDate } from './common.js'
import { optionCookie } from './cookie.js'
import md5 from 'md5'
import { remoteLinkAddress } from './ip.js'

var RemoteAdd = remoteLinkAddress()

function objKeySort (obj) {
  var newkey = Object.keys(obj).sort()
  var newObj = {}
  for (var i = 0; i < newkey.length; i++) {
    newObj[newkey[i]] = obj[newkey[i]]
  }
  return newObj //返回排好序的新对象
}

function searchMap (key) {
  var map = new Map()

  //链接管理
  map.set('LINK_ADD', 'link.add')
  map.set('LINK_EDIT', 'link.edit')
  map.set('LINK_DEL', 'link.del')
  map.set('LINK_LISTALL', 'link.listall')
  map.set('LINK_LIST', 'link.listpage')
  map.set('LINK_GET', 'link.get')
  map.set('ACCOUT_LIST', 'passport.account.listpage')
  map.set('ACCOUT_BASEINFO', 'account.baseinfo')
  map.set('ACCOUT_ROLES', 'account.roles')//获取用户的所有角色
  map.set('ACCOUT_MENUS', 'account.menus')//获取用户的某子系统下的菜单

  //实名认证身份信息
  map.set('PUBLIC_CREDENTIALS_ADD', 'public.credentials.add')
  map.set('PUBLIC_CREDENTIALS_GET', 'public.credentials.get')
  map.set('PUBLIC_CREDENTIALS_GETBYTYPE', 'public.credentials.getbytype')
  //信息完善
  map.set('PERSONAL_GET', 'hm.personal.get')
  map.set('PERSONAL_EDIT', 'hm.personal.edit')
  map.set('COMPANY_GET', 'hm.company.get')
  map.set('COMPANY_EDIT', 'hm.company.edit')
  map.set('PERSONAL_CLASS_GET', 'hlhr.expert.id.get')//获取专家的类别（高级人才或外国专家）
  //文件上传
  map.set('ATTACHMENT_UPLOAD', 'attachmentfiles.upload')
  map.set('IMAGE_UPLOAD', 'imagefiles.upload')
  map.set('PERSONAL_PORTRAIT_ADD', 'hm.personal.portrait.add')
  map.set('COMPANY_PORTRAIT_ADD', 'hm.company.license.add')
  //账户系统
  map.set('USER_REGISTER', 'passport.account.regist')
  map.set('USER_GET', 'passport.account.get')
  map.set('CAPCHA_CHECK', 'passport.capcha.check')
  map.set('USER_LOGIN', 'passport.token.get')
  map.set('PASSWORD_RESET', 'passport.password.reset')
  map.set('TOKEN_REFRESH', 'passport.token.refresh')
  map.set('CAPCHA_GET', 'passport.capcha.get')
  map.set('CONTRACT_BIND', 'passport.contract.bind')
  map.set('CONTRACT_UNBIND', 'passport.contract.unbind')
  map.set('CONTRACT_EDIT', 'passport.contract.edit')
  map.set('USER_LOGOUT', 'passport.token.delete')
  map.set('ROLE_USER_LIST', 'role.user.list')
  //子系统部分API
  map.set('SUBSYS_ADD', 'subsys.add')
  map.set('SUBSYS_EDIT', 'subsys.edit')
  map.set('SUBSYS_DEL', 'subsys.del')
  map.set('SUBSYS_LISTALL', 'subsys.listall')
  map.set('SUBSYS_LIST', 'subsys.listpage')
  map.set('SUBSYS_GET', 'subsys.get')
  //
  map.set('SUBSYS_APIURI_LISTPAGE', 'sys.apiuri.listpage')
  map.set('SUBSYS_APIURI_ADD', 'sys.apiuri.add')
  map.set('SUBSYS_APIURI_DEL', 'sys.apiuri.del')
  map.set('SUBSYS_APIURI_GET', 'sys.apiuri.get')
  map.set('SUBSYS_APIURI_EDIT', 'sys.apiuri.edit')
  map.set('SUBSYS_APIURI_LISTALL', 'sys.apiuri.listall')
  // 菜单部分
  map.set('MENU_ADD', 'menu.add')
  map.set('MENU_EDIT', 'menu.edit')
  map.set('MENU_DEL', 'menu.del')
  map.set('MENU_LISTALL', 'menu.listall')
  map.set('MENU_LIST', 'menu.listpage')
  map.set('MENU_GET', 'menu.get')
  //子系统操作类型
  map.set('OPERTYPE_ADD', 'opertype.add')
  map.set('OPERTYPE_EDIT', 'opertype.edit')
  map.set('OPERTYPE_DEL', 'opertype.del')
  map.set('OPERTYPE_LISTALL', 'opertype.listall')
  map.set('OPERTYPE_LIST', 'opertype.listpage')
  map.set('OPERTYPE_GET', 'opertype.get')
  //角色部分API
  map.set('ROLE_ADD', 'role.add')
  map.set('ROLE_EDIT', 'role.edit')
  map.set('ROLE_DEL', 'role.del')
  map.set('ROLE_LISTALL', 'role.listall')
  map.set('ROLE_LIST', 'role.listpage')
  map.set('ROLE_GET', 'role.get')
  map.set('ROLE_LISTUSER', 'role.listuser')
  map.set('ROLE_SETRIGHT', 'role.right.set')
  map.set('ROLE_GETRIGHT', 'role.right.get')
  map.set('ROLE_ADDUSER', 'role.user.addr')//一个用户多个角色
  map.set('ROLE_DELUSER', 'role.deluser')
  map.set('ROLE_USER_ROLE', 'role.user.role')
  map.set('ROLE_RIGHT_GET', 'role.right.get')//获取用户权限

  ////服务预约类型
  map.set('RESERVATION_TYPE_ADD', 'hlhr.reservation.type.add')
  map.set('RESERVATION_TYPE_EDIT', 'hlhr.reservation.type.edit')
  map.set('RESERVATION_TYPE_DEL', 'hlhr.reservation.type.del')
  map.set('RESERVATION_TYPE_GET', 'hlhr.reservation.type.get')
  map.set('RESERVATION_TYPE_LISTALL', 'hlhr.reservation.type.listall')
  map.set('RESERVATION_TYPE_LIST', 'hlhr.reservation.type.listpage')
  map.set('RESERVATION_TYPE_DETAILLISTPAGE', 'hlhr.reservation.type.detaillistpage')
  map.set('RESERVATION_TYPE_MANAGER_ADD', 'hlhr.reservation.type.user.add')//增加服务管理员
  map.set('RESERVATION_TYPE_MANAGER_DEL', 'hlhr.reservation.type.user.del')//删除服务管理员
  map.set('RESERVATION_TYPE_MANAGER_LIST', 'hlhr.reservation.type.user.list')//服务管理员列表
  /////服务政策
  map.set('RESERVATION_STATUTES_ADD', 'hlhr.reservation.statutes.add')
  map.set('RESERVATION_STATUTES_PUBLISH', 'hlhr.reservation.statutes.publish')
  map.set('RESERVATION_STATUTES_UNPUBLISH', 'hlhr.reservation.statutes.unpublish')
  map.set('RESERVATION_STATUTES_EDIT', 'hlhr.reservation.statutes.edit')
  map.set('RESERVATION_STATUTES_DEL', 'hlhr.reservation.statutes.del')
  map.set('RESERVATION_STATUTES_GET', 'hlhr.reservation.statutes.get')
  map.set('RESERVATION_STATUTES_DOWNLOAD', 'hlhr.reservation.statutes.download')
  map.set('RESERVATION_STATUTES_LISTALL', 'hlhr.reservation.statutes.listall')
  map.set('RESERVATION_STATUTES_LIST', 'hlhr.reservation.statutes.listpage')
  ////预约服务办理接口
  map.set('RESERVATION_ORDER_ADD', 'hlhr.reservation.order.add')//服务预约新增
  map.set('RESERVATION_ORDER_EDIT', 'hlhr.reservation.order.edit')//服务预约编辑
  map.set('RESERVATION_ORDER_CANCEL', 'hlhr.reservation.order.cancel')//取消服务预约
  map.set('RESERVATION_ORDER_GET', 'hlhr.reservation.order.get')//查询单个服务预约
  map.set('RESERVATION_ORDER_LISTALL', 'hlhr.reservation.order.listall')//查询所有服务预约
  map.set('RESERVATION_ORDER_LIST', 'hlhr.reservation.order.listpage')//分页查询服务预约
  map.set('RESERVATION_ORDER_DOWNLOAD', 'hlhr.reservation.order.download')//下载服务预约
  //预约服务批复
  map.set('RESERVATION_ORDER_REPLY', 'hlhr.reservation.order.reply')

  //国籍
  map.set('NATIONALITY_LISTALL', 'nationality.listall')

  //职称分类
  map.set('TECHTITLE_CLASS_LIST', 'hlhr.techtitle.class.listpage')//
  map.set('TECHTITLE_CLASS_LISTALL', 'hlhr.techtitle.class.listall')//
  map.set('TECHTITLE_CLASS_GET', 'hlhr.techtitle.class.get')//
  map.set('TECHTITLE_CLASS_EDIT', 'hlhr.techtitle.class.edit')//
  map.set('TECHTITLE_CLASS_DEL', 'hlhr.techtitle.class.del')//
  map.set('TECHTITLE_CLASS_ADD', 'hlhr.techtitle.class.add')//

  //职称
  map.set('HLHR_TECHTITLE_TITLE_LIST', 'hlhr.techtitle.title.listpage')//新增
  map.set('HLHR_TECHTITLE_TITLE_ADD', 'hlhr.techtitle.title.add')//新增
  map.set('HLHR_TECHTITLE_TITLE_EDIT', 'hlhr.techtitle.title.edit')//编辑
  map.set('HLHR_TECHTITLE_TITLE_DEL', 'hlhr.techtitle.title.del')//编辑
  map.set('HLHR_TECHTITLE_TITLE_DELALL', 'hlhr.techtitle.title.delall')//删除
  map.set('HLHR_TECHTITLE_TITLE_GET', 'hlhr.techtitle.title.get')//获取职称
  map.set('HLHR_TECHTITLE_TITLE_LISTALLL', 'hlhr.techtitle.title.listall')//请求职称

  //单位所在区域
  map.set('HLHR_UNIT_AREA_LIST', 'hlhr.unit.area.listpage')//新增
  map.set('HLHR_UNIT_AREA_ADD', 'hlhr.unit.area.add')//新增
  map.set('HLHR_UNIT_AREA_EDIT', 'hlhr.unit.area.edit')//编辑
  map.set('HLHR_UNIT_AREA_DEL', 'hlhr.unit.area.del')//删除
  map.set('HLHR_UNIT_AREA_GET', 'hlhr.unit.area.get')//获取单位所在区域
  map.set('HLHR_UNIT_AREA_LISTALL', 'hlhr.unit.area.listall')//请求单位所在区域

  //专家类别
  map.set('HLHR_EXPERT_CLASS_LIST', 'hlhr.expert.class.listpage')//新增
  map.set('HLHR_EXPERT_CLASS_ADD', 'hlhr.expert.class.add')//新增
  map.set('HLHR_EXPERT_CLASS_EDIT', 'hlhr.expert.class.edit')//编辑
  map.set('HLHR_EXPERT_CLASS_DEL', 'hlhr.expert.class.del')//删除
  map.set('HLHR_EXPERT_CLASS_GET', 'hlhr.expert.class.get')//获取专家类别
  map.set('HLHR_EXPERT_CLASS_LISTALL', 'hlhr.expert.class.listall')//请求专家类别

  //专业技术人员信息管理
  map.set('HLHR_TECHNICIST_ADD', 'hlhr.technicist.add')//新增
  map.set('HLHR_TECHNICIST_EDIT', 'hlhr.technicist.edit')//编辑
  map.set('HLHR_TECHNICIST_LIST', 'hlhr.technicist.listpage')
  map.set('HLHR_TECHNICIST_DEL', 'hlhr.technicist.del')//删除
  map.set('HLHR_TECHNICIST_VERIFY', 'hlhr.technicist.verify')//审核
  map.set('HLHR_TECHNICIST_DOWNLOAD', 'hlhr.technicist.download')//下载
  map.set('HLHR_TECHNICIST_GET', 'hlhr.technicist.get')//获取技术人员信息
  map.set('HLHR_TECHNICIST_LISTALL', 'hlhr.technicist.listall')//请求技术人员信息
  map.set('HLHR_TECHNICIST_GETBYIDCARD', 'hlhr.expert.id.technicistinfo.idcard')//根据身份证查询

  //行业序列
  map.set('HLHR_VOCATION_ADD', 'hlhr.vocation.add')//新增
  map.set('HLHR_VOCATION_EDIT', 'hlhr.vocation.edit')//编辑
  map.set('HLHR_VOCATION_LIST', 'hlhr.vocation.listpage')
  map.set('HLHR_VOCATION_DEL', 'hlhr.vocation.del')//删除
  map.set('HLHR_VOCATION_GET', 'hlhr.vocation.get')//
  map.set('HLHR_VOCATION_LISTALL', 'hlhr.vocation.listall')//

  //个人简历
  map.set('HM_RESUME_ADD', 'hm.resume.add')//新增
  map.set('HM_RESUME_EDIT', 'hm.resume.edit')//编辑
  map.set('HM_RESUME_DEL', 'hm.resume.del')//删除
  map.set('HM_RESUME_COPY', 'hm.resume.copy')//复制
  map.set('HM_RESUME_GET', 'hm.resume.get')//获取
  map.set('HM_RESUME_LISTALL', 'hm.resume.listall')//请求个人简历
  map.set('HM_RESUME_DELIVERY_COMPANY_GET', 'hm.resume.delivery.company.get')//公司查看建立详情
  map.set('HM_RESUME_DELIVERY_COMPANY_EDIT', 'hm.resume.delivery.company.edit')//公司查看建立详情
  map.set('HM_RESUME_DELIVERY_COMPANY_LISTPAGE', 'hm.resume.delivery.company.listpage')//公司查看建立详情
  map.set('HM_RESUME_DELIVERY_ADD', 'hm.resume.delivery.add')//增加
  map.set('HM_RESUME_DELIVERY_LISTPAGE', 'hm.resume.delivery.listpage')//列表
  map.set('HM_RESUME_DELIVERY_DEL', 'hm.resume.delivery.del')//删除
  //个人简历基本信息部分
  map.set('HM_RESUME_PERSONAL_EDIT', 'hm.resume.personal.edit')//修改
  map.set('HM_RESUME_PERSONAL_GET', 'hm.resume.personal.get')//修改
  //个人简历工作经历部分
  map.set('HM_RESUME_WORKS_EDIT', 'hm.resume.works.edit')
  map.set('HM_RESUME_WORKS_LISTALL', 'hm.resume.works.listall')
  map.set('HM_RESUME_WORKS_GET', 'hm.resume.works.get')
  map.set('HM_RESUME_WORKS_ADD', 'hm.resume.works.add')
  map.set('HM_RESUME_WORKS_DEL', 'hm.resume.works.del')
  //个人简历项目经验部分
  map.set('HM_RESUME_PROJECTS_EDIT', 'hm.resume.projects.edit')
  map.set('HM_RESUME_PROJECTS_LISTALL', 'hm.resume.projects.listall')
  map.set('HM_RESUME_PROJECTS_GET', 'hm.resume.projects.get')
  map.set('HM_RESUME_PROJECTS_ADD', 'hm.resume.projects.add')
  map.set('HM_RESUME_PROJECTS_DEL', 'hm.resume.projects.del')
  map.set('HM_RESUME_PROJECTS_IMG_ADD', 'hm.resume.projects.img.add')//项目作品
  //个人简历培训经历部分
  map.set('HM_RESUME_TRAIN_EDIT', 'hm.resume.train.edit')//修改
  map.set('HM_RESUME_TRAIN_LISTALL', 'hm.resume.train.listall')
  map.set('HM_RESUME_TRAIN_GET', 'hm.resume.train.get')
  map.set('HM_RESUME_TRAIN_ADD', 'hm.resume.train.add')
  map.set('HM_RESUME_TRAIN_DEL', 'hm.resume.train.del')
  map.set('HM_RESUME_TRAIN_IMG_ADD', 'hm.resume.train.img.add')//培训证书照片
  //个人简历教育经历部分
  map.set('HM_RESUME_EDUCATION_EDIT', 'hm.resume.education.edit')
  map.set('HM_RESUME_EDUCATION_LISTALL', 'hm.resume.education.listall')
  map.set('HM_RESUME_EDUCATION_GET', 'hm.resume.education.get')
  map.set('HM_RESUME_EDUCATION_ADD', 'hm.resume.education.add')
  map.set('HM_RESUME_EDUCATION_DEL', 'hm.resume.education.del')
  map.set('HM_RESUME_DIPLOMA_ADD', 'hm.resume.diploma.add') //教育证书上传
  //个人简历职称技能部分
  map.set('HM_RESUME_CERTIFICATE_EDIT', 'hm.resume.certificate.edit')//修改
  map.set('HM_RESUME_CERTIFICATE_LISTALL', 'hm.resume.certificate.listall')//修改
  map.set('HM_RESUME_CERTIFICATE_GET', 'hm.resume.certificate.get')//修改
  map.set('HM_RESUME_CERTIFICATE_ADD', 'hm.resume.certificate.add')//修改
  map.set('HM_RESUME_CERTIFICATE_DEL', 'hm.resume.certificate.del')//修改
  map.set('HM_RESUME_CERTIFICATE_IMG_ADD', 'hm.resume.certificate.img.add')//技能证书图片
  //个人简历求职意向部分
  map.set('HM_RESUME_OBJECTIVE_EDIT', 'hm.resume.objective.edit')
  map.set('HM_RESUME_OBJECTIVE_LISTALL', 'hm.resume.objective.listall')
  map.set('HM_RESUME_OBJECTIVE_GET', 'hm.resume.objective.get')
  map.set('HM_RESUME_OBJECTIVE_ADD', 'hm.resume.objective.add')
  map.set('HM_RESUME_OBJECTIVE_DEL', 'hm.resume.objective.del')

  //企业发布
  map.set('HM_COMPANY_JOB_EDIT', 'hm.company.job.edit')
  map.set('HM_COMPANY_JOB_GET', 'hm.company.job.get')
  map.set('HM_COMPANY_JOB_ADD', 'hm.company.job.add')
  map.set('HM_COMPANY_JOB_DEL', 'hm.company.job.del')
  map.set('HM_COMPANY_JOB_LISTPAGE', 'hm.company.job.listpage')
  map.set('HM_COMPANY_JOB_LISTALLBYNAME', 'hm.company.job.listallbyname')

  //工作邀请(企业用户)
  map.set('HM_COMPANY_INTERVIEW_ADD', 'hm.center.interview.company.add')
  map.set('HM_COMPANY_INTERVIEW_LISTPAGE', 'hm.center.interview.company.listpage')
  map.set('HM_COMPANY_INTERVIEW_GET', 'hm.center.interview.company.get')
  map.set('HM_COMPANY_INTERVIEW_DEL', 'hm.center.interview.company.del')
  map.set('HM_COMPANY_INTERVIEW_EDIT', 'hm.center.interview.company.edit')
  map.set('HM_COMPANY_INTERVIEW_VIEW', 'hm.center.interview.company.interviewtype.listpage')

  //工作邀请(个人用户)
  map.set('HM_PERSONAL_INTERVIEW_LISTPAGE', 'hm.center.interview.personal.listpage')
  map.set('HM_PERSONAL_INTERVIEW_GET', 'hm.center.interview.personal.get')
  map.set('HM_PERSONAL_INTERVIEW_EDIT', 'hm.center.interview.personal.edit')
  map.set('HM_PERSONAL_INTERVIEW_VIEW', 'hm.center.interview.personal.interviewtype.listpage')

  //统计结果
  map.set('HM_STATISTICS_INTERVIEW_COUNT', 'hm.statistics.interview.count')
  map.set('HM_STATISTICS_RESUME_COUNT', 'hm.statistics.resume.count')
  map.set('HM_STATISTICS_JOB_COUNT', 'hm.statistics.job.count')
  //人才市场
  map.set('HM_RESUME_JOBS_LIST', 'hm.center.jobs.listpage')
  map.set('HM_RESUME_TALENTS_LIST', 'hm.center.talents.listpage')

  //角色管理
  map.set('GET_AUTH_FILE', 'file.auth')

  //省市区
  map.set('PROVINCE_LISTCASCADE', 'province.listcascade')
  map.set('PROVINCE_LISTALL', 'province.listall')//省
  map.set('CITY_LISTALL', 'city.listall')//市
  map.set('DISTRICT_LISTALL', 'district.listall')//市

  //职位类别
  map.set('POSTITION_LISTALL', 'hm.common.position.listall')
  map.set('POSITION_LISTALLBYID', 'hm.common.position.listallbyid')

  map.set('SCHOOL_LISTALL', 'hm.common.school.listall')//学校列表

  map.set('NATION_LISTALL', 'nation.listall')//民族
  map.set('HM_COMMON_INDUSTRY_LISTALL', 'hm.common.industry.listall')//查询所有单位行业

  map.set('COMPANY_MANAGE_LISTPAGE', 'hm.company.manage.listpage')//公司管理
  map.set('HM_COMPANY_USER_GET', 'hm.company.user.get')//通过企业id查询用户基础表
  map.set('HM_COMPANY_USER_EDIT', 'hm.company.user.edit')//通过企业id查询用户基础表

  //网络摊位管理
  map.set('STALLS_NET_ADD', 'hm.stalls.net.add')
  map.set('STALLS_NET_EDIT', 'hm.stalls.net.edit')
  map.set('STALLS_NET_DEL', 'hm.stalls.net.del')
  map.set('STALLS_NET_LISTPAGE', 'hm.stalls.net.listpage')
  map.set('STALLS_NET_LISTALL', 'hm.stalls.net.listall')
  map.set('STALLS_NET_GET', 'hm.stalls.net.get')
  map.set('STALLS_NET_LIKE_LISTPAGE', 'hm.stalls.net.like.listpage')

  //摊位排期管理
  map.set('STALLS_SCHEDULE_ADD', 'hm.stalls.schedule.add')
  map.set('STALLS_SCHEDULE_DEL', 'hm.stalls.schedule.del')
  map.set('STALLS_SCHEDULE_LISTPAGE', 'hm.stalls.schedule.listpage')
  map.set('STALLS_SCHEDULE_GET', 'hm.stalls.schedule.get')
  map.set('STALLS_SCHEDULE_DAY_LISTALL', 'hm.stalls.schedule.day.listall')
  map.set('STALLS_SCHEDULE_LISTALL', 'hm.stalls.schedule.listall')
  map.set('STALLS_SCHEDULE_ANY_LISTALL', 'hm.stalls.schedule.any.listall')
  map.set('STALLS_SCHEDULE_STATUS_LISTPAGE', 'hm.stalls.schedule.status.listpage')

  //企业发布招聘信息管理
  map.set('COMPANY_PROGRAM_ADD', 'hm.company.program.add')
  map.set('COMPANY_PROGRAM_DEL', 'hm.company.program.del')
  map.set('COMPANY_PROGRAM_EDIT', 'hm.company.program.edit')
  map.set('COMPANY_PROGRAM_LISTALL', 'hm.company.program.listall')
  map.set('COMPANY_PROGRAM_ALL_LISTALL', 'hm.company.program.all.listall')
  map.set('COMPANY_PROGRAM_JOB_ADD', 'hm.company.program.job.add')
  map.set('COMPANY_PROGRAM_JOB_DEL', 'hm.company.program.job.del')

  //套餐管理(服务类型管理)
  map.set('PACKAGE_SERVICE_TYPE_ADD', 'hm.package.service.type.add')
  map.set('PACKAGE_SERVICE_TYPE_EDIT', 'hm.package.service.type.edit')
  map.set('PACKAGE_SERVICE_TYPE_DEL', 'hm.package.service.type.del')
  map.set('PACKAGE_SERVICE_TYPE_LIST', 'hm.package.service.type.listpage')
  //（计费项管理）
  map.set('STALLS_BILLING_ITEMS_ADD', 'hm.package.billing.items.add')
  map.set('STALLS_BILLING_ITEMS_EDIT', 'hm.package.billing.items.edit')
  map.set('STALLS_BILLING_ITEMS_DEL', 'hm.package.billing.items.del')
  map.set('STALLS_BILLING_ITEMS_LIST', 'hm.package.billing.items.listpage')
  //（计费方式管理）
  map.set('STALLS_BILLING_METHOD_ADD', 'hm.package.billing.method.add')
  map.set('STALLS_BILLING_METHOD_EDIT', 'hm.package.billing.method.edit')
  map.set('STALLS_BILLING_METHOD_DEL', 'hm.package.billing.method.del')
  map.set('STALLS_BILLING_METHOD_LIST', 'hm.package.billing.method.listpage')
  //（服务项管理）
  map.set('STALLS_SERVICE_ITEM_ADD', 'hm.package.service.item.add')
  map.set('STALLS_SERVICE_ITEM_EDIT', 'hm.package.service.item.edit')
  map.set('STALLS_SERVICE_ITEM_DEL', 'hm.package.service.item.del')
  map.set('STALLS_SERVICE_ITEM_LIST', 'hm.package.service.item.listpage')
  map.set('STALLS_SERVICE_ITEM_SET', 'hm.package.service.item.set')
  map.set('STALLS_SERVICE_ITEM_GET', 'hm.package.service.item.get')

  //缴费明细列表（套餐缴费，摊位缴费）
  //套餐缴费
  map.set('PACKAGE_ORDER_LISTALL', 'hm.package.order.listall')
  map.set('PACKAGE_ORDER_LISTPAGE', 'hm.package.order.listpage')
  map.set('PACKAGE_ORDER_GET', 'hm.package.order.get')
  map.set('PACKAGE_ORDER_DEL', 'hm.package.order.del')

  //套餐管理
  map.set('PACKAGE_ADD', 'hm.package.add')
  map.set('PACKAGE_DEL', 'hm.package.del')
  map.set('PACKAGE_GET', 'hm.package.get')
  map.set('PACKAGE_EDIT', 'hm.package.edit')
  map.set('PACKAGE_LISTPAGE', 'hm.package.listpage')
  map.set('PACKAGE_DETAIL_PACKAGE_LISTPAGE', 'hm.package.Detail.listpage')
  map.set('PACKAGE_DETAIL_ADD', 'hm.package.Detail.add')
  map.set('PACKAGE_DETAIL_GET', 'hm.package.Detail.get')
  map.set('PACKAGE_DETAIL_GETBY_PACKAGEID', 'hm.package.Detail.getby.packageId')//获取已选择的服务项列表
  map.set('PACKAGE_DETAIL_DELBY_PACKAGEID', 'hm.package.Detail.delby.packageid')//删除全部已选择的服务项列表

  map.set('PACKAGE_ORDER_ADD', 'hm.package.order.add')//新增套餐订单
  map.set('PACKAGE_ORDER_USE_GET', 'hm.package.order.use.get')//套餐使用情况
  map.set('PACKAGE_ORDER_USE_ADD', 'hm.package.order.use.add')//套餐使用情况
  map.set('PACKAGE_ORDER_USE_BYPACKID_ADD', 'hm.package.order.use.bypackid.add')//套餐使用情况

  //假期管理
  map.set('HOLIDAY_ADD', 'hm.holiday.add')
  map.set('HOLIDAY_EDIT', 'hm.holiday.edit')
  map.set('HOLIDAY_DEL', 'hm.holiday.del')
  map.set('HOLIDAY_LISTALL', 'hm.holiday.listall')
  map.set('HOLIDAY_LISTPAGE', 'hm.holiday.listpage')

  //公司
  map.set('HM_COMPANY_LISTPAGE', 'hm.company.listpage')
  return map.get(key)
}

function URLConstruct (key) {
  var s = searchMap(key)
  var m = methodToURL(s)
  return RemoteAdd + m
}

function methodToURL (name) {
  var _url = ''
  while (name.indexOf('.') >= 0) {
    name = name.replace('.', '/')
  }
  _url = name
  return _url
}

function createSign (key, userParam, datatype) {
  if (typeof(userParam) === undefined) {
    userParam = {}
  }
  if (localStorage.getItem('lang') === 'en-us') {
    userParam.language = 'English'
  }
  if (typeof(datatype) === undefined) {
    datatype = 'json'
  }
  var data = Object()

  if (optionCookie('get', 'access_token') !== '-1') {
    data.session = optionCookie('get', 'access_token')
  }
  // else
  // {
  //   data.session="";
  // }
  var sk = 'CvvPuOpsU1f05gSuDyFyA5yjKESgux1o'
  data.method = searchMap(key)
  data.timestamp = getNowFormatDate()
  data.app_key = 'H9vUQm8nmwn9uNmg2ibRDp0BRm32R2qS'
  data.version = '1.0'
  data.encrypt_method = 'md5'
  for (var m in userParam) {
    if (userParam[m] !== undefined) {
      data[m] = userParam[m]
    }

  }
  if (datatype == 'json') {
    data.format = 'json'
  }

  var sortdata = objKeySort(data)
  var str = ''
  var encryptStr = ''
  for (var s in sortdata) {
    str += s + sortdata[s]
  }
  str = sk + str + sk
  encryptStr = md5(str)
  encryptStr = encryptStr.toUpperCase()
  data.sign = encryptStr
  return data
}

function trimParam (userParam) {
  for (var param in userParam) {
    if (typeof(userParam[param]) === 'string') {
      userParam[param] = userParam[param].replace(/^\s+|\s+$/g, '')
    }
  }
  return userParam
}

export function postDataToServer (key, userParam) {
  if (typeof(userParam) === undefined) {
    userParam = {}
  }
  userParam = trimParam(userParam)
  var sendData = createSign(key, userParam)
  var _url = URLConstruct(key)
  return axios.post(_url, sendData)
    .then(function (response) {
      return response.data
    })
}

export function getDataFromServer (key, url, userParam) {
  if (typeof(userParam) === undefined) {
    userParam = {}
  }
  var sendData = createSign(key, userParam)
  var index = 0
  for (var s in sendData) {
    if (index == 0) {
      url += '?' + s + '=' + sendData[s]
      index++
    }
    else {
      url += '&' + s + '=' + sendData[s]
      index++
    }
  }
  window.open(url, '_blank')
  return axios.get(url)
    .then(function (response) {
      return response.data
    })
}

export function getImgFromServer (key, url) {
  var userParam = getDownParams(url)
  if ('file_auth' in userParam && userParam.file_auth === 'true') {
    var downUrl = userParam.downurl
    delete userParam.downurl
    var sendData = createSign(key, userParam)
    var index = 0
    for (var s in sendData) {
      if (index == 0) {
        downUrl += '?' + s + '=' + sendData[s]

        index++
      }
      else {
        downUrl += '&' + s + '=' + sendData[s]
        index++
      }
    }
    return downUrl
  } else {
    return url
  }
}

function getQueryString (down_url) {
  var urlinfo = down_url
  var len = urlinfo.length
  var offset = urlinfo.indexOf('?')
  if (offset == -1) {
    return undefined
  }
  var newsidinfo = urlinfo.substr(offset + 1, len)
  var newinfo = newsidinfo.split('&')
  var MultiID = {}
  for (var i = 0; i < newinfo.length; i++) {
    var newsids = newinfo[i].split('=')
    MultiID[newsids[0]] = newsids[1]
  }
  return MultiID
}

function getDownParams (down_url) {
  var user_Param = {}
  var m = getQueryString(down_url)
  user_Param.file_auth = m.file_auth
  user_Param.file_expires = m.file_expires
  user_Param.file_sign = m.file_sign
  m = down_url.split('?')
  user_Param.downurl = m[0]
  return user_Param
}

export function createUploadUrl (type, userParam) {
  if (typeof(userParam) === undefined) {
    userParam = {}
  }
  var _url
  var key
  switch (type) {
    case 'ATTACHMENT':
      key = 'ATTACHMENT_UPLOAD'
      break
    case 'IMAGE':
      key = 'IMAGE_UPLOAD'
      break
    case 'HeadPortrait':
      key = 'PERSONAL_PORTRAIT_ADD'
      break
    default:
      key = type
      break
  }
  _url = URLConstruct(key)
  var data = Object()
  data = createSign(key, userParam, 'file')
  var str = ''
  var index = 0
  for (var s in data) {
    if (index == 0) {
      str += '?' + s + '=' + data[s]
    }
    else {
      str += '&' + s + '=' + data[s]
    }
    index = index + 1
  }
  _url += str
  return _url
}

export function getFileServer (key, url, userParam) {
  if (typeof(userParam) === undefined) {
    userParam = {}
  }
  var sendData = createSign(key, userParam)
  var index = 0
  for (var s in sendData) {
    if (index == 0) {
      url += '?' + s + '=' + sendData[s]
      index++
    }
    else {
      url += '&' + s + '=' + sendData[s]
      index++
    }
  }
  return url
}

